package com.hrhx.duhongming.adapter;

import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.AxisType;
import com.github.abel533.echarts.code.LineType;
import com.github.abel533.echarts.code.Position;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Scatter;
import com.hrhx.duhongming.bean.EchartsConfig;

public class EchartsScatterAdapter implements EchartsAdapter{
	
	//scatter的适配器入口
	public static GsonOption adapter(EchartsConfig echartsConfig,
			GsonOption gsonOption,
			Object[][] data){
		EchartsScatterAdapter barAdapter = new EchartsScatterAdapter();
		gsonOption = barAdapter.xyAxisAdapter(gsonOption);
		gsonOption = barAdapter.seriesAdapter(echartsConfig,gsonOption,data);
		return gsonOption;
	}
	
	
	//x轴配置和Y轴配置
	public GsonOption xyAxisAdapter(GsonOption gsonOption){
		ValueAxis valueAxis = new ValueAxis();
		valueAxis.type(AxisType.value);
		valueAxis.splitLine().lineStyle().type(LineType.dashed);
		gsonOption.xAxis(valueAxis);
		gsonOption.yAxis(valueAxis);
		return gsonOption;
	}
	
	//Y轴数据处理
	@SuppressWarnings("unchecked")
	public GsonOption seriesAdapter(EchartsConfig echartsConfig,GsonOption gsonOption,Object[][] data){
		Scatter scatter = new Scatter();
		scatter.name("scatter")
			   .label().emphasis().show(true)
			   					  .position(Position.left)
			   					  .textStyle().color("blue").fontSize(16);
		for (int num = 0; num < data.length; num++) {
			scatter.data().add(data[num]);
		};
		gsonOption.series(scatter);
		return gsonOption;
	}
}
